package com.example.demo.controller;

import com.example.demo.dto.OrderDto;
import com.example.demo.dto.OrderItemDto;
import com.example.demo.model.Result;
import com.example.demo.service.OrdersService;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/orders")
@RestController
public class OrdersController {

    private OrdersService ordersService;

    public OrdersController(OrdersService ordersService) {
        this.ordersService = ordersService;
    }

//    //根据用户ID获取所有的订单信息
//    @GetMapping("/{id}")
//    public Result getOrdersById(@PathVariable("id") Integer id){
//        return ordersService.getOrdersById(id);
//    }
    //根据订单的状态和用户id获取订单的信息
    @PostMapping
    public Result getOrdersByStatus(@RequestBody OrderDto orderDto){
        return ordersService.getOrdersByStatus(orderDto);
    }


    @PutMapping()
    public Result cancalOrder(@RequestBody OrderDto orderDto) {
        System.out.println(orderDto);
        ordersService.cancalOrderUpdateInfo(orderDto);
        return Result.buildSuccess();
    }

    @PostMapping("/e")
    public Result addOrdersByStatus(@RequestBody OrderItemDto orderItemDto) {
        ordersService.addOrderItem(orderItemDto);
        return Result.buildSuccess(ordersService.findOne(orderItemDto));
    }
}
